package com.example.ordersystem.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.example.ordersystem.R;
import com.example.ordersystem.pojo.Store;

import java.util.List;

/*
 * 该适配器是为了展示店铺列表（listView）
 */
public class StoreAdapter extends ArrayAdapter {
    private final int resourceId;

    public StoreAdapter(Context context, int textViewResourceId, List<Store> objects) {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Store store = (Store) getItem(position); // 获取当前项的Store实例
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);//实例化一个对象
        ImageView storeImage = view.findViewById(R.id.store_image);
        TextView storeName = view.findViewById(R.id.store_name);
        storeImage.setImageResource(store.getImageId());
        storeName.setText(store.getStoreName());
        return view;
    }


}
